package com.emagic.manage.modules.room.presenter;

import android.util.Log;

import com.emagic.manage.data.entities.response.Empty;
import com.emagic.manage.modules.room.domain.GetOutSendGiftUseCase;
import com.emagic.manage.modules.room.view.GiftsView;
import com.emagic.manage.mvp.presenters.Presenter;
import com.emagic.manage.mvp.views.InterfaceView;
import com.xitaiinfo.library.injections.ActivityScope;

import java.util.Map;

import javax.inject.Inject;

import rx.Subscriber;

/**
 * Created by xiatian on 2017/12/4.
 */
@ActivityScope
public class SendGiftPresenter implements Presenter {
    private GiftsView view;
    private String TAG = SendGiftPresenter.class.getSimpleName();
    private GetOutSendGiftUseCase getOutSendGiftUseCase;

    @Inject
    public SendGiftPresenter(GetOutSendGiftUseCase getOutSendGiftUseCase) {
        this.getOutSendGiftUseCase = getOutSendGiftUseCase;
    }

    @Override
    public void onResume() {

    }

    @Override
    public void onPause() {

    }

    @Override
    public void onDestroy() {
        getOutSendGiftUseCase.unSubscribe();
    }

    @Override
    public void attachView(InterfaceView v) {
        this.view = (GiftsView) v;
    }

    public void sendGift(String serial, Map studios) {
        getOutSendGiftUseCase.setSerial(serial);
        getOutSendGiftUseCase.setStudios(studios);
        getOutSendGiftUseCase.execute(new Subscriber<Empty>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {
                Log.e(TAG, "onError: " + e.getMessage());
                view.dissmiss("1");
            }

            @Override
            public void onNext(Empty empty) {
                view.dissmiss("0");
            }
        });
    }
}
